﻿Imports IIsManager

Module modTest

    Sub Main()

        'Test1()
        Test2()
        Test3()

    End Sub

    Sub Test1()

        Dim IIsSvc As IIsService = Nothing

        Try

            IIsSvc = New IIsService

            ' Creating a testsite, setting ASP.NET Version, setting directory Access Permissions.
            Using testsite = IIsSvc.AddSite("TestSite", "c:\inetpub\testsite", "test.site.nl")

                testsite.AccessPermissions = AccessPermissionFlags.Read + AccessPermissionFlags.Script

                Console.WriteLine(testsite.ASPNETVersion.ToString)

                Console.ReadLine()

                testsite.ASPNETVersion = ASPNETVersions.v2_0_50727

                Console.WriteLine(testsite.ASPNETVersion.ToString)

                Using images = testsite.AddDirectory("images")
                    images.AccessPermissions = AccessPermissionFlags.Read + AccessPermissionFlags.Write
                End Using

                Console.ReadLine()

                IIsSvc.RemoveSite(testsite.Id)

            End Using

            ' Selecting an existing site, creating an application.
            Using template = (From s In IIsSvc.Sites Where s.Description = "TemplateSite" Select s).First

                Using vdnonapp = (From d In template.VirtualDirectories Where d.Name = "vdnonapp" Select d).First

                    vdnonapp.CreateApplication("bla")

                    Console.ReadLine()

                    vdnonapp.DeleteApplication()

                End Using

            End Using


        Catch ex As Exception

            Console.WriteLine(ex.Message & vbNewLine & vbNewLine & If(ex.InnerException Is Nothing, ex.StackTrace, ex.InnerException.Message & vbNewLine & vbNewLine & ex.InnerException.StackTrace))
            Console.ReadLine()

        Finally

            If Not IIsSvc Is Nothing Then IIsSvc.Dispose()

        End Try


    End Sub

    Sub Test2()

        Console.Write("Description: ")

        Dim desc = Console.ReadLine()

        Using myService = New IIsService
            Using mySite = myService.Sites.Single(Function(s) s.Description = desc)

                If mySite IsNot Nothing Then

                    Console.Write("ASP.NET version: ")
                    Console.Write(mySite.ASPNETVersion.ToString)

                Else

                    Console.Write("Site not found..")

                End If

                Console.ReadLine()

            End Using

        End Using

    End Sub

    Sub Test3()

        Console.Write("Description: ")

        Dim desc = Console.ReadLine()

        Using myService = New IIsService
            Using mySite = myService.Sites.Single(Function(s) s.Description = desc)

                If mySite IsNot Nothing Then

                    mySite.ASPNETVersion = ASPNETVersions.v4_0_30319
                    Console.Write("Set to v4.0")
                    Console.ReadLine()

                    mySite.ASPNETVersion = ASPNETVersions.v2_0_50727
                    Console.Write("Set to v2.0")

                    Console.ReadLine()

                Else

                    Console.Write("Site not found..")

                End If

                Console.ReadLine()

            End Using

        End Using

    End Sub

End Module
